<template>
  <div>
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="代理名称">
                <a-input v-model="queryParam.name" placeholder=""/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="代理手机号">
                <a-input v-model="queryParam.phone" placeholder=""/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="代理等级">
                <a-select v-model="queryParam.level" placeholder="请选择" default-value="">
                  <a-select-option value="">全部</a-select-option>
                  <a-select-option value="1">群主</a-select-option>
                  <a-select-option value="2">精英</a-select-option>
                  <a-select-option value="3">大咖</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button
                  type="primary"
                  @click="$refs.table.refresh(true)"
                >查询</a-button>
                <a-button style="margin-left: 8px" @click="handleReset">重置</a-button>
                <!--                <a-button style="margin-left: 8px" >导出</a-button>-->
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <s-table
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :scroll="{ x: 1300 }"
        :data="loadData"
        showPagination="auto"
      >
        <span slot="balance" slot-scope="text, agent">
          <span style="color: red;">{{ agent.balance | formatAmount }}</span>
        </span>
        <span slot="unextractable_balance" slot-scope="text, agent">
          <span style="color: red;">{{ agent.unextractable_balance | formatAmount }}</span>
        </span>

        <span slot="action" slot-scope="text, agent">
          <template>
            <a
              @click="$router.push({
                name: 'agent_profit_running_bill',
                params: { id: agent.id },
                query: { name: agent.name, phone: agent.phone }
            })">流水明细</a>
          </template>
        </span>
      </s-table>
    </a-card>
  </div>
</template>

<script>
  import { STable } from '@/components'
  import PartnersForm from '@/views/proxy/partner/Form'
  import { getAgentList } from '@/api/agent'

  export default {
    name: 'List',
    components: {
      PartnersForm,
      STable
    },
    data () {
      return {
        // 查询参数
        queryParam: {},
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: 'id'
          },
          {
            title: '代理手机号',
            dataIndex: 'phone'
          },
          {
            title: '代理名称',
            dataIndex: 'name'
          },
          {
            title: '等级',
            dataIndex: 'level',
            customRender: level => this.levelMap[level].text
          },
          {
            title: '可提现余额',
            scopedSlots: { customRender: 'balance' }
          },
          {
            title: '不可提现余额',
            scopedSlots: { customRender: 'unextractable_balance' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            fixed: 'right',
            width: '150px',
            scopedSlots: { customRender: 'action' }
          }
        ],
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          return getAgentList(Object.assign(parameter, this.queryParam)).then(res => {
            return res
          })
        },
        selectedRowKeys: [],
        selectedRows: [],
        levelMap: this.$store.getters.levelMap
      }
    },
    created () {

    },
    methods: {
      handleReset () {
        this.queryParam = {}
      }
    }
  }
</script>
